package CoreJavaKnow;

import java.math.BigInteger;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

public class MD5Test {

	public static void main(String[] args) {

		String toEnc = "andrew"; // Value to encrypt
		//System.out.println(EncryptionUtil.md5(toEnc));
		//System.out.println(EncryptionUtil.md5(toEnc));
		try {
			MessageDigest mdEnc = MessageDigest.getInstance("MD5"); // Encryption algorithm
			mdEnc.update(toEnc.getBytes(), 0, toEnc.length());
			byte[] hashed = mdEnc.digest();
			for (byte b : hashed) {
				System.out.print(b + " ");
			}

			System.out.println("");
			String md5 = new BigInteger(1, hashed).toString(16); // Encrypted string
			System.out.println(md5);
		} catch (NoSuchAlgorithmException e) {
			e.printStackTrace();
		}

		
	}
}
